package com.baichang.taoshunda.controller.mobile.business;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.BussinessReplyService;
import com.baichang.taoshunda.service.GoodsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(ControllerConstants.BUSSINESSCOMMENT)
public class BussinessCommentMController extends BaseMobileController {

    @Autowired
    private BussinessReplyService bussinessReplyService;

    @Autowired
    private GoodsCommentService goodsCommentService;

    /**
     * 查看商家评论列表
     *
     * @param request
     * @param response
     */
    @RequestMapping("/findCommentList")
    public void findCommentList(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer bussId = getInt(json, "bussId", 0);
                Integer nowPage = getInt(json, "nowPage", 1);
                Integer pageSize = getInt(json, "pageSize", 20);
                return bussinessReplyService.findCommentList(bussId, nowPage, pageSize);
            }
        });
    }

    /**
     * 添加追评回复
     *
     * @param request
     * @param response
     */
    @RequestMapping("/reviewReply")
    public void reviewReply(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer commentId = getInt(json, "commentId", 0);
                String reviewReply = getString(json, "reviewReply", "");
                return goodsCommentService.reviewReply(commentId, reviewReply);
            }
        });
    }

    /**
     * 添加评论回复
     *
     * @param request
     * @param response
     */
    @RequestMapping("/commentReply")
    public void review(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer commentId = getInt(json, "commentId", 0);
                String commentReply = getString(json, "commentReply", "");
                return goodsCommentService.commentReply(commentId, commentReply);
            }
        });
    }
}
